﻿/*************************************************************
 * Software of blackcore
 *
 * CLRVersion:4.0.30319.586
 * MachineName:SPACE
 * Author:Andy Huang
 * Email:itblackhole@gmail.com
 * DateTime：6/19/2013 3:35:26 PM
 * Function：
 *************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace SobFS.Web.ashx
{
    /// <summary>
    /// Summary description for backend
    /// </summary>
    public class backend : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //执行行为
            string executeAction = context.Request.QueryString["executeAction"];

            switch (executeAction)
            {
                //加载菜单项
                case "LoadUserFunctionMenu":
                    LoadUserFunctionMenus(context);
                    break;
                //加载系统插件
                case "LoadUserPlugins":
                    LoadUserPlugins(context);
                    break;
            }

        }


        /// <summary>
        /// 加载用户功能菜单
        /// </summary>
        /// <param name="context"></param>
        private void LoadUserFunctionMenus(HttpContext context)
        {
            StringBuilder menus = new StringBuilder ();

            menus.AppendLine("[{\"text\":\"新闻资讯\",\"isexpand\":\"false\",\"children\":[{\"text\":\"内容管理\",\"url\":\"article/list.aspx?channel_id=1\"},{\"text\":\"栏目类别\",\"url\":\"category/list.aspx?channel_id=1\"},{\"text\":\"扩展属性\",\"url\":\"attribute/list.aspx?channel_id=1\"}]},{\"text\":\"购物商城\",\"isexpand\":\"false\",\"children\":[{\"text\":\"内容管理\",\"url\":\"goods/list.aspx?channel_id=2\"},{\"text\":\"栏目类别\",\"url\":\"category/list.aspx?channel_id=2\"},{\"text\":\"扩展属性\",\"url\":\"attribute/list.aspx?channel_id=2\"}]},{\"text\":\"图片分享\",\"isexpand\":\"false\",\"children\":[{\"text\":\"内容管理\",\"url\":\"article/list.aspx?channel_id=3\"},{\"text\":\"栏目类别\",\"url\":\"category/list.aspx?channel_id=3\"},{\"text\":\"扩展属性\",\"url\":\"attribute/list.aspx?channel_id=3\"}]},{\"text\":\"资源下载\",\"isexpand\":\"false\",\"children\":[{\"text\":\"内容管理\",\"url\":\"download/list.aspx?channel_id=4\"},{\"text\":\"栏目类别\",\"url\":\"category/list.aspx?channel_id=4\"}]},{\"text\":\"公司介绍\",\"isexpand\":\"false\",\"children\":[{\"text\":\"内容管理\",\"url\":\"content/list.aspx?channel_id=5\"},{\"text\":\"栏目类别\",\"url\":\"category/list.aspx?channel_id=5\"}]}]");

            context.Response.Write(menus.ToString ());
        }

        /// <summary>
        /// 加载用户可用插件
        /// </summary>
        /// <param name="context"></param>
        private void LoadUserPlugins(HttpContext context)
        {
            List<Model.SysFunctionMenu> models = new BLL.SysFunctionMenu().GetModelList("MenuType = '" + SobFS.Common.SobFSConst.MenuType.Plug + "' AND IsObsoleted = 0 AND IsEnabled = 1");
            StringBuilder plugins = new StringBuilder();                                       
            if (models != null && models.Count > 0)
            {
                foreach (Model.SysFunctionMenu model in models)
                {
                    plugins.AppendLine(string.Format("<li><a class=\"l-link\" href=\"javascript:f_addTab('plug{0}','{1}','{2}')\">{3}</a></li>\n", model.Code, model.Name, model.URL, model.Name));
                }
            }
            context.Response.Write(plugins.ToString());
        }



        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}